package com.zhike.api.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhike.common.dto.ConfigDTO;
import com.zhike.common.dto.R;
import com.zhike.service.system.ISystemConfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

@Api(tags = "配置模块")
@RestController
@RequestMapping("api/zkim/config")
public class ConfigController {

    @Autowired
    private ISystemConfigService systemConfigService;

    @ApiModelProperty("同步并更新一条配置")
    @PostMapping("syncOne")
    public R<Boolean> syncOneConfig(@Validated ConfigDTO dto) {
        return R.success(systemConfigService.syncCache(dto.getConfigType(), dto.getConfigKey(), dto.getConfigVal()));
    }

    @ApiOperation(value = "同步更新所有配置项")
    @PostMapping("syncAll")
    public void syncAll() {
        systemConfigService.syncCacheAll();
    }

}
